/**
 * 
 */
package org.dragonfire.dasm.instr;

/**
 * A <code>Register</code> defines a set of bits that are common to a register
 * and are used throughout multiple commands. Each <code>Register</code> has a
 * class, or group, ID number that groups all similar register definitions
 * together that are interchangable. An <code>Instruction</code> simply
 * specifies a class ID number for a given parameter and all registers that have
 * that same class ID number are valid to fill that parameter.
 * 
 * @author Darth Android
 * @date Nov 30, 2006
 */
public class Register implements Comparable<Register> {

	private String name = "";
	private int classID = 0;
	private String bits = "";

	/**
	 * Returns the binary string of data that is substituted in for this
	 * register
	 * 
	 * @return The binary string for this register
	 */
	public String getBits() {
		return bits;
	}

	/**
	 * Returns the name of this register
	 * 
	 * @return The name of this register
	 */
	public String getName() {
		return name;
	}

	/**
	 * Returns the class of this register
	 * 
	 * @return The class of this register
	 */
	public int getClassID() {
		return classID;
	}

	/**
	 * Constructs a new register definition
	 * 
	 * @param name
	 *            The name of the register
	 * @param classID
	 *            The class of the register
	 * @param bits
	 *            The binary string for this register
	 */
	public Register(String name, int classID, String bits) {
		this.name = name;
		this.classID = classID;
		this.bits = bits;
	}

	public String toString() {
		return getName().toUpperCase() + " {class=" + getClassID() + ",bits=" + getBits() + "}";
	}

	public int compareTo(Register r) {
		if (!r.getName().equalsIgnoreCase(getName()))
			return getName().compareToIgnoreCase(r.getName());
		return getClassID() - r.getClassID();
	}
}
